<?php
require_once '../../../wp-blog-header.php';
header('HTTP/1.0 200 OK');

$is_ajax_valid = check_ajax_referer('newsletter_ajax_pref','ajax_nonce_pref');

if($is_ajax_valid == 1){
	
	$pod_item_id = $_POST['pod_item_id'];
	$columns_newsletter['cities'] = $_POST['newsletter_city_pref'];
	$columns_newsletter['categories'] = $_POST['allCats'];
	
	$is_daily = $_POST['newsletter_daily'];
	$is_weekly = $_POST['newsletter_weekly'];
	
	if($is_daily == 'true'){
		$columns_newsletter['daily'] = 1;
	}else{
		$columns_newsletter['daily'] = 0;
	}
	
	if($is_weekly == 'true'){
		$columns_newsletter['weekly'] = 1;
	}else{
		$columns_newsletter['weekly'] = 0;
	}
	
	$api = new PodAPI();
	$params_newsletter = array('datatype' => 'newsletter', 'tbl_row_id' => $pod_item_id, 'columns' => $columns_newsletter);
	$api->save_pod_item($params_newsletter);
	
	echo "Success";
}else{
	echo 'Page open since too long, please reload to subscribe to the newsletters!';
}
?>
